package day03;

import java.util.HashSet;
import java.util.Objects;

public class HashSetExercise {
    public static void main(String[] args) {
        HashSet set = new HashSet();
        set.add(new Employee("milan",3000,new MyDate(2000,12,4)));
        set.add(new Employee("tom",2000,new MyDate(2001,11,5)));
        set.add(new Employee("tom",5000,new MyDate(2001,11,5)));
        for (Object o :set) {
            System.out.println(o);
        }

    }
}
class MyDate {
    private int year;
    private int mouth;
    private int day;

    public MyDate(int year, int mouth, int day) {
        this.year = year;
        this.mouth = mouth;
        this.day = day;
    }

    @Override
    public String toString() {
        return year +"-"+ mouth + "-"+ day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && mouth == myDate.mouth && day == myDate.day;
    }

    @Override
    public int hashCode() {
        return 0;
    }
}
class Employee {
    private String name;
    private double sal;
    private MyDate birth;

    public Employee(String name, double sal, MyDate birth) {
        this.name = name;
        this.sal = sal;
        this.birth = birth;
    }

    @Override
    public String toString() {
        return name + "\t\t" + sal + "\t\t"+ birth;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return name.equals(employee.name) && birth.equals(employee.birth);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birth);
    }
}
